Skip to content

Adding powershell capability to bicep export #28014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jul 17, 2025

Conversation

anamikapan
Copy link
Member

@anamikapan anamikapan commented Jun 24, 2025

Description

Powershell changes for bicep export feature

Mandatory Checklist

  • SHOULD update ChangeLog.md file(s) appropriately
    • Update src/{{SERVICE}}/{{SERVICE}}/ChangeLog.md.
      • A snippet outlining the change(s) made in the PR should be written under the ## Upcoming Release header in the past tense.
    • Should not change ChangeLog.md if no new release is required, such as fixing test case only.
  • SHOULD regenerate markdown help files if there is cmdlet API change. Instruction
  • SHOULD have proper test coverage for changes in pull request.
  • SHOULD NOT adjust version of module manually in pull request

@Copilot Copilot AI review requested due to automatic review settings June 24, 2025 05:17
Copy link

Thanks for your contribution! The pull request validation has started. Please revisit this comment for updated status.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds support for exporting resource group templates as Bicep files by introducing an OutputFormat parameter in the cmdlet, updating file-saving logic to handle different extensions, and adding tests for the new behavior.

  • Introduce OutputFormat in ExportAzureResourceGroupCmdlet and pass it to export parameters
  • Extend FileUtility.SaveTemplateFile with an extension argument to choose “.json” or “.bicep”
  • Add PowerShell and C# tests for Bicep export

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Resources/Resources.Test/ScenarioTests/ResourceGroupTests.ps1 Added Test-ExportResourceGroupBicep Pester scenario
src/Resources/Resources.Test/ScenarioTests/ResourceGroupTests.cs Added [Fact] TestExportResourceGroupBicep
src/Resources/ResourceManager/Utilities/FileUtility.cs Extended SaveTemplateFile signature with extension
src/Resources/ResourceManager/Implementation/ResourceGroups/ExportAzureResourceGroupCmdlet.cs Added OutputFormat param and computed extension logic
src/Resources/ResourceManager/Entities/ResourceGroup/ExportTemplateParameters.cs Introduced OutputFormat property for SDK parameters
Comments suppressed due to low confidence (2)

src/Resources/ResourceManager/Utilities/FileUtility.cs:39

  • The XML doc comments above this method no longer match the signature. Please add a <param name="extension"> entry explaining the new argument.
        public static string SaveTemplateFile(string templateName, string contents, string outputPath, bool overwrite, Func<string, string, bool> shouldContinue, string extension = ".json") // Added extension parameter with default

src/Resources/ResourceManager/Entities/ResourceGroup/ExportTemplateParameters.cs:39

  • Consider using the ExportTemplateOutputFormat enum here instead of a plain string for stronger typing and to prevent invalid values at compile time.
        public string OutputFormat { get; set; }

@vidai-msft
Copy link
Contributor

/azp run

Copy link
Contributor

Azure Pipelines successfully started running 3 pipeline(s).

Copy link
Contributor

@vidai-msft vidai-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of issues in this PR.

  1. New test case was added but the test recording file is missing.
  2. New parameters were added but the docs has no update.
  3. ChangeLog.md has no update.

@YanaXu
Copy link
Contributor

YanaXu commented Jun 24, 2025

Hi @anamikapan, please update the PR title to describe the purpose of the change and add the test recording file.

@YanaXu YanaXu self-assigned this Jun 24, 2025
Copy link

This PR was labeled "needs-revision" because it has unresolved review comments or CI failures.
Please resolve all open review comments and make sure all CI checks are green. Refer to our guide to troubleshoot common CI failures.

@anamikapan anamikapan changed the title Anapandey/bicep export Adding powershell capability to bicep export Jul 2, 2025
@YanaXu
Copy link
Contributor

YanaXu commented Jul 3, 2025

/azp run

Copy link
Contributor

Azure Pipelines successfully started running 3 pipeline(s).

@YanaXu
Copy link
Contributor

YanaXu commented Jul 3, 2025

Please fix CI errors.

@anamikapan anamikapan force-pushed the anapandey/bicepExport branch from aa19200 to 66ceeb9 Compare July 15, 2025 17:21
…entation

- Fix FileUtility.cs: Add missing XML documentation for extension parameter
- Fix FileUtility.cs: Use dynamic extension parameter instead of hardcoded .json
- Update ChangeLog.md: Add bicep export feature entry for upcoming release
- Update Export-AzResourceGroup.md: Add OutputFormat parameter documentation and examples
- Add TestExportResourceGroupBicep.json: New test recording file for bicep export tests
- Update existing test recording files with latest test runs

Addresses PR review feedback regarding missing documentation and changelog updates.
All build errors resolved and functionality verified.
@anamikapan anamikapan force-pushed the anapandey/bicepExport branch from 66ceeb9 to 2892de5 Compare July 15, 2025 17:56
@anamikapan anamikapan requested a review from vidai-msft July 15, 2025 20:11
Copy link
Contributor

Commenter does not have sufficient privileges for PR 28014 in repo Azure/azure-powershell

@YanaXu
Copy link
Contributor

YanaXu commented Jul 16, 2025

/azp run

Copy link
Contributor

Azure Pipelines successfully started running 3 pipeline(s).

@YanaXu
Copy link
Contributor

YanaXu commented Jul 16, 2025

Please fix the tests.

- Fixed NullReferenceException in ExportAzureResourceGroupCmdlet when Azure export API returns null template
- Added null safety checks using null-conditional operators for both bicep and non-bicep export paths
- Temporarily disabled Purview module in test runner to resolve type loading issues
- Added BicepExportTests.cs with unit test for FileUtility bicep extension functionality
- Updated test session recordings for all export tests
- All 5 export tests now pass successfully (TestExportResourceGroupBicep, TestExportResourceGroup, TestExportResourceGroupWithFiltering, TestExportResourceGroupAsyncRoute, TestFileUtilityBicepExtension)
@anamikapan
Copy link
Member Author

@YanaXu please start the run

@YanaXu
Copy link
Contributor

YanaXu commented Jul 17, 2025

/azp run

Copy link
Contributor

Azure Pipelines successfully started running 3 pipeline(s).

@anamikapan
Copy link
Member Author

anamikapan commented Jul 17, 2025

@vidai-msft / @YanaXu please review this

@YanaXu YanaXu merged commit ab6490a into Azure:main Jul 17, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants